Revising the Select Query 2 hackerrank solution in sql